package cn.zebra.dev.config.spring.web.client;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

/**
 * @author runnable@sina.cn
 */
@Configuration
public class RestTemplateAutoConfigureBean {

    /**
     * 连接请求超时设置
     */
    private Integer connectionRequestTimeout = 30 * 1000;
    /**
     * 连接超时设置
     */
    private Integer connectTimeout = 30 * 3000;
    /**
     * 读取超时设置
     */
    private Integer readTimeOut = 30 * 3000;

    @Bean
    public RestTemplate restTemplate() {
        HttpComponentsClientHttpRequestFactory httpRequestFactory = new HttpComponentsClientHttpRequestFactory();
        httpRequestFactory.setConnectionRequestTimeout(this.connectionRequestTimeout);
        httpRequestFactory.setConnectTimeout(this.connectTimeout);
        httpRequestFactory.setReadTimeout(this.readTimeOut);
        return new RestTemplate(httpRequestFactory);
    }

}
